home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 326-350 / disk_337 / cmanual / idcmp.lzh / IDCMP / Example4.c < prev    next >
C/C++ Source or Header  |  1990-01-30  |  6KB  |  173 lines

  1. /* Example4                                                    */
  2. /* This program explains how to use the IDCMP flag SIZEVERIFY. */
  3.  
  4.  
  5.  
  6. #include <intuition/intuition.h>
  7.  
  8.  
  9.  
  10. struct IntuitionBase *IntuitionBase;
  11.  
  12.  
  13.  
  14. /* Declare a pointer to a Window structure: */ 
  15. struct Window *my_window;
  16.  
  17. /* Declare and initialize your NewWindow structure: */
  18. struct NewWindow my_new_window=
  19. {
  20.   50,             /* LeftEdge    x position of the window. */
  21.   25,             /* TopEdge     y positio of the window. */
  22.   320,            /* Width       320 pixels wide. */
  23.   100,            /* Height      100 lines high. */
  24.   0,              /* DetailPen   Text should be drawn with colour reg. 0 */
  25.   1,              /* BlockPen    Blocks should be drawn with colour r. 1 */
  26.   CLOSEWINDOW|    /* IDCMPFlags  We will recieve a message when the user: */
  27.                   /*             selects the Close window gad.            */
  28.  
  29.   SIZEVERIFY,     /*             We will also recieve a verifying message */
  30.                   /*             when the user resizes the window.        */
  31.                   /*             However, the window will change size     */
  32.                   /*             first when we have replied.              */
  33.  
  34.   SMART_REFRESH|  /* Flags       Intuition should refresh the window. */
  35.   WINDOWCLOSE|    /*             Close Gadget. */
  36.   WINDOWDRAG|     /*             Drag gadget. */
  37.   WINDOWDEPTH|    /*             Depth arrange Gadgets. */
  38.   WINDOWSIZING|   /*             Sizing Gadget. */
  39.   ACTIVATE,       /*             The window should be Active when opened. */
  40.   NULL,           /* FirstGadget No gadgets connected to this window. */
  41.   NULL,           /* CheckMark   Use Intuition's default CheckMark. */
  42.   "RESIZABLE WINDOW", /* Title   Title of the window. */
  43.   NULL,           /* Screen      Connected to the Workbench Screen. */
  44.   NULL,           /* BitMap      No Custom BitMap. */
  45.   100,            /* MinWidth    We will not allow the window to become */
  46.   50,             /* MinHeight   smaller than 100 x 50, and not bigger */
  47.   400,            /* MaxWidth    than 400 x 200. */
  48.   200,            /* MaxHeight */
  49.   WBENCHSCREEN    /* Type        Connected to the Workbench Screen. */
  50. };
  51.  
  52.  
  53.  
  54. /*************************************************************************/
  55. /* Extra information:                                                    */
  56. /* When we recieve a SIZEVERIFY message we may finish off with something */
  57. /* before we allow Intuition to resize the window. The window will first */
  58. /* be resized when we have replied.                                      */
  59. /*************************************************************************/
  60.  
  61.  
  62.  
  63. main()
  64. {
  65.   /* Boolean variable used for the while loop: */
  66.   BOOL close_me;
  67.  
  68.   ULONG class; /* IDCMP flag. */
  69.  
  70.   /* Pointer to an IntuiMessage structure: */
  71.   struct IntuiMessage *my_message;
  72.  
  73.  
  74.  
  75.   /* Before we can use Intuition we need to open the Intuition Library: */
  76.   IntuitionBase = (struct IntuitionBase *)
  77.     OpenLibrary( "intuition.library", 0 );
  78.   
  79.   if( IntuitionBase == NULL )
  80.     exit(); /* Could NOT open the Intuition Library! */
  81.  
  82.  
  83.  
  84.   /* We will now try to open the window: */
  85.   my_window = (struct Window *) OpenWindow( &my_new_window );
  86.   
  87.   /* Have we opened the window succesfully? */
  88.   if(my_window == NULL)
  89.   {
  90.     /* Could NOT open the Window! */
  91.     
  92.     /* Close the Intuition Library since we have opened it: */
  93.     CloseLibrary( IntuitionBase );
  94.  
  95.     exit();  
  96.   }
  97.  
  98.  
  99.  
  100.   /* We have opened the window, and everything seems to be OK. */
  101.  
  102.   printf("Try to resize the window!\n\n");
  103.  
  104.  
  105.  
  106.   close_me = FALSE;
  107.  
  108.   /* Stay in the while loop until the user has selected the Close window */
  109.   /* gadget: */
  110.   while( close_me == FALSE )
  111.   {
  112.     /* Wait until we have recieved a message: */
  113.     Wait( 1 << my_window->UserPort->mp_SigBit );
  114.  
  115.  
  116.     /* As long as we can collect messages successfully we stay in the */
  117.     /* while-loop: */
  118.     while(my_message = (struct IntuiMessage *) GetMsg(my_window->UserPort))
  119.     {
  120.       /* After we have successfully collected the message we can read */
  121.       /* it, and save any important values which we maybe want to check */
  122.       /* later: */
  123.       class = my_message->Class;  /* IDCMP flag. */
  124.  
  125.  
  126.       /* Check if we have recieved a SIZEVERIFY message: */
  127.       if( class == SIZEVERIFY )
  128.       {
  129.         /* The user tries to resize the window. However, it will first */
  130.         /* change size when we have replied, so we may finish of with  */
  131.         /* something before. We will now take a little pause, just to  */
  132.         /* show that we can control the resizing of the window:        */
  133.         printf("So you tried to resize the window! Tough luck!\n");
  134.         printf("Here I decide when you may resize it, and I want\n");
  135.         printf("to take a pause...\n");
  136.       
  137.         /* Wait 2 seconds: */
  138.         Delay( 2 * 50 );
  139.         
  140.         printf("OK! You may now resize the window.\n\n");
  141.         /* Once we reply the window will be resized. */
  142.       }
  143.  
  144.  
  145.       /* After we have read it we reply as fast as possible: */
  146.       /* REMEMBER! Do never try to read a message after you have replied! */
  147.       /* (Some other process has maybe changed it.) */
  148.       ReplyMsg( my_message );
  149.  
  150.  
  151.       /* Check which IDCMP flag was sent: */
  152.       switch( class )
  153.       {
  154.         case CLOSEWINDOW:    /* The user selected the Close window gad. */
  155.                close_me=TRUE;
  156.                break;
  157.       }
  158.     }
  159.   }
  160.  
  161.  
  162.  
  163.   /* Close the window: */
  164.   CloseWindow( my_window );
  165.  
  166.  
  167.  
  168.   /* Close the Intuition Library: */
  169.   CloseLibrary( IntuitionBase );
  170.   
  171.   /* THE END */
  172. }
  173.